package edu.nf.redis_retry.service;

import edu.nf.redis_retry.config.RabbitConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

/*
* 死信端 消费者
* */
@Service
@Slf4j
public class DeadConsumerService {
    /*
     * 使用@RabbitListener绑定死信队列和交换机
     * @param message
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = RabbitConfig.DEAD_QUEUE_NAME, durable = "false"),
            exchange = @Exchange(name = RabbitConfig.DEAD_EXCHANGE_NAME, type = ExchangeTypes.DIRECT),
            key = RabbitConfig.DEAD_ROUTING_KEY
    ))
    public void receiveDeadMessage(String message) {
        log.info("接收死信消息: {}", message);
    }
}
